import { onMounted, onUnmounted } from "vue"

export default  function useScroll(){
    const scrollListenerHandler = () => {
        const clientHeight = document.documentElement.clientHeight
        const scrollTop = document.documentElement.scrollTop
        const scrollHeight = document.documentElement.scrollHeight
        if(clientHeight + scrollTop >= scrollHeight){
            homeStore.fetchHouseListData()
        }
    }
    onMounted(() => {
        window.addEventListener("scroll", scrollListenerHandler)
    })
    
    
    onUnmounted(() => {
        window.removeEventListener("scroll", scrollListenerHandler)
    })
}